﻿using XSot.BitBrowser.LocalApiClient.Model;

namespace XSot.BitBrowser.LocalApiClient
{
    partial class BitBrowserLocalApiClient
    {
        /// <summary>
        /// 获取分组详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<HttpResult<BitBrowserGroupProfile>> GetGroupProfile(string id)
        {
            var req = new { id };

            return GetResponseAsync<BitBrowserGroupProfile>("/group/detail", req);
        }
        /// <summary>
        /// 查询分组列表接口,page 从 0 开始
        /// </summary>
        /// <param name="page">分页， 从 0 开始</param>
        /// <param name="pageSize">每页条数，最大 100 条，传入大于 100 的数字，也最多返回 100 条数据</param>
        /// <param name="all">是否获取权限范围内的所有分组</param>
        /// <returns></returns>
        public Task<HttpResult<BitBrowserPageList<BitBrowserGroupProfile>>> GetGroupList(int page = 0, int pageSize = 10, bool all = true)
        {
            page = Math.Min(100, Math.Max(page, 0));
            pageSize = Math.Min(100, Math.Max(pageSize, 1));

            var req = new { page, pageSize, all };

            return GetResponseAsync<BitBrowserPageList<BitBrowserGroupProfile>>("/group/list", req);
        }
        /// <summary>
        /// 修改分组
        /// </summary>
        /// <param name="id"></param>
        /// <param name="groupName"></param>
        /// <param name="sortNum"></param>
        /// <returns></returns>
        public Task<HttpResult<BitBrowserGroupProfile>> UpdateGroup(string id, string groupName, int sortNum = 0)
        {
            var req = new { id, groupName, sortNum };

            return GetResponseAsync<BitBrowserGroupProfile>("/group/edit", req);
        }
        /// <summary>
        /// 删除分组
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<HttpResult<string>> DeleteGroup(string id)
        {
            var req = new { id };

            return GetResponseAsync<string>("/group/delete", req);
        }
    }
}